﻿
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Jemer.Domain;
using Jemer.Data;
using Jemer.Data.Infrastructure;
using Jemer.Domain.Entities;
using Jemer.Data.Repositories;

namespace Jemer.Service
{
    
    public interface IProductImgService
    {
        IQueryable<ProductImg> GetProductImgs();
        ProductImg GetProductImg(int id);
        void CreateProductImg(ProductImg productImg);
        void DeleteProductImg(int id);
        void SaveProductImg();
    }
    
    public class ProductImgService : IProductImgService
    {
        private readonly IProductImgRepository productImgRepository;
        private readonly IUnitOfWork unitOfWork;
        public ProductImgService(IProductImgRepository productImgRepository, IUnitOfWork unitOfWork)
        {
            this.productImgRepository = productImgRepository;
            this.unitOfWork = unitOfWork;
        }  
        #region IProductImgService Members

        public IQueryable<ProductImg> GetProductImgs()
        {
            var productImgs = productImgRepository.GetAll();
            return productImgs;
        }

        public ProductImg GetProductImg(int id)
        {
            var productImg = productImgRepository.GetById(id);
            return productImg;
        }

        public void CreateProductImg(ProductImg productImg)
        {
            productImgRepository.Add(productImg);
            SaveProductImg();
        }

        public void DeleteProductImg(int id)
        {
            var productImg = productImgRepository.GetById(id);
            productImgRepository.Delete(productImg);
            SaveProductImg();
        }

        public void SaveProductImg()
        {
            unitOfWork.Commit();
        }

        #endregion
    }
    
    
}